package com.artisan.util;

import java.util.Random;

public class RandomUtil {
    /// <summary>
    /// 生成随机字母与数字
    /// </summary>
    /// <param name="ran"></param>
    /// <param name="length">生成长度</param>
    /// <param name="sleep">是否要在生成前将当前线程阻止以避免重复</param>
    public static String Str(int length)
    {
        char[] pattern = new char[]
                {
                        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
                        'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
                };
        String result = "";
        int n = pattern.length;
        Random random = new Random();
        for (int i = 0; i < length; i++)
        {
            int rnd = random.nextInt(n);
            result += pattern[rnd];
        }
        return result;
    }
}
